package com.digital.welcome.controller;


import com.alibaba.fastjson.JSON;
import com.digital.welcome.entity.User;
import com.digital.welcome.mapper.UserRoleMapper;
import com.digital.welcome.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 韩
 */
@RestController
@RequestMapping("/user-role")
public class UserRoleController {

    @Autowired
    private UserRoleMapper userRoleMapper;

    @ApiOperation("用户角色查询")
    @RequestMapping(value = "/select", method = RequestMethod.POST)
    public String selectUser(@RequestBody User user) {
        List<String> allRoleByUserName = userRoleMapper.getAllRoleByUserName(user.getUserName());
        if (allRoleByUserName != null) {
            return JSON.toJSONString(new Result<>().setCode(200).setMessage("查询成功").setData(allRoleByUserName));
        } else {
            return JSON.toJSONString(new Result<>().setCode(400).setMessage("无角色"));
        }

    }

}
